//
//  SLUserStateViewController.m
//  StarLight
//
//  Created by apple on 16/8/17.
//  Copyright © 2016年 Duke.Wu. All rights reserved.
//

#import "SLUserStateViewController.h"

@interface SLUserStateViewController ()

/**
 *  船东
 */
@property (nonatomic ,strong) UIButton *ShipownerBtn;
/**
 *  货主
 */
@property (nonatomic ,strong) UIButton *CargoOwnerBtn;

@end

@implementation SLUserStateViewController

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:NO animated:YES];
}
- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    [self.navigationController setNavigationBarHidden:YES animated:YES];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:self.ShipownerBtn];
    [self.view addSubview:self.CargoOwnerBtn];
    
    
    [self.ShipownerBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.view);
        make.bottom.mas_equalTo(-(SCREEN_HEIGHT / 3) * 2);
        make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH / 3, 30));
    }];
    [self.CargoOwnerBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.view);
        make.bottom.mas_equalTo(-(SCREEN_HEIGHT / 3) * 1);
        make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH / 3, 30));
    }];    
}

- (void)changeUserShipownerState
{
    [DEFAULTS setObject:@(0) forKey:@"userType"];
    [DEFAULTS synchronize];
    [[NSNotificationCenter defaultCenter] postNotificationName:kCHANGETYPE object:[DEFAULTS objectForKey:@"userType"]];
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)changeUserCargoOwnerState
{
    [DEFAULTS setObject:@(1) forKey:@"userType"];
    [DEFAULTS synchronize];
    [[NSNotificationCenter defaultCenter] postNotificationName:kCHANGETYPE object:[DEFAULTS objectForKey:@"userType"]];
    [self.navigationController popViewControllerAnimated:YES];
}

- (UIButton *)ShipownerBtn{
    if (!_ShipownerBtn) {
        _ShipownerBtn  = [UIButton buttonWithType:UIButtonTypeCustom];
        _ShipownerBtn.titleLabel.font = bFont(14);
        [_ShipownerBtn setTitle:@"船东" forState:UIControlStateNormal];
        _ShipownerBtn.layer.borderColor = RGBCOLOR(253,207,0).CGColor;
        _ShipownerBtn.layer.borderWidth = 1;
        _ShipownerBtn.layer.cornerRadius = 5;
        _ShipownerBtn.layer.masksToBounds = YES;
        [_ShipownerBtn setTitleColor:RGBCOLOR(253,207,0) forState:UIControlStateNormal];
        [_ShipownerBtn addTarget:self action:@selector(changeUserShipownerState) forControlEvents:UIControlEventTouchUpInside];
    }
    return _ShipownerBtn;
}

- (UIButton *)CargoOwnerBtn{
    if (!_CargoOwnerBtn) {
        _CargoOwnerBtn  = [UIButton buttonWithType:UIButtonTypeCustom];
        _CargoOwnerBtn.titleLabel.font = bFont(14);
        [_CargoOwnerBtn setTitle:@"货主" forState:UIControlStateNormal];
        _CargoOwnerBtn.layer.borderColor = RGBCOLOR(253,207,0).CGColor;
        _CargoOwnerBtn.layer.borderWidth = 1;
        _CargoOwnerBtn.layer.cornerRadius = 5;
        _CargoOwnerBtn.layer.masksToBounds = YES;
        [_CargoOwnerBtn setTitleColor:RGBCOLOR(253,207,0) forState:UIControlStateNormal];
        [_CargoOwnerBtn addTarget:self action:@selector(changeUserCargoOwnerState) forControlEvents:UIControlEventTouchUpInside];
    }
    return _CargoOwnerBtn;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
